package com.wuhunyu.utils;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
 * OSS常量配置
 *
 * @author wuhunyu
 * @version 1.0
 * @date 2021-01-15 21:49
 */
@Component
@ConfigurationProperties(prefix = "aliyun.oss")
@PropertySource("classpath:application.yml")
public class ConstantPropertiesUtils implements InitializingBean {

    @Value("${endpoint}")
    private String endpoint;

    @Value("${accessKeyId}")
    private String accessKeyId;

    @Value("${accessKeySecret}")
    private String accessKeySecret;

    @Value("${bucketName}")
    private String bucketName;

    @Value("${url}")
    private String url;

    public static String ENDPOINT;

    public static String ACCESS_KEY_ID;

    public static String ACCESS_KEY_SECRET;

    public static String BUCKET_NAME;

    public static String URL;

    /**
     * ConstantPropertiesUtils类加载到spring容器中之后执行的方法
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        ENDPOINT = endpoint;
        ACCESS_KEY_ID = accessKeyId;
        ACCESS_KEY_SECRET = accessKeySecret;
        BUCKET_NAME = bucketName;
        URL = url;
    }
}
